#define _CRT_SECURE_NO_WARNINGS 1
#include"Stack.h"
void STInit(ST* st)
{
	assert(st);
	st->arr = NULL;
	st->top = st->capacity = 0;
}
void STEnough(ST* st)
{
	assert(st);
	if (st->top == st->capacity)
	{
		int newcapacity = st->capacity == 0 ? 4 : 2 * st->capacity;
		STDataType* tmp = (STDataType*)realloc(st->arr, sizeof(STDataType) * newcapacity);
		if (tmp == NULL)
		{
			perror("malloc fail!");
			exit(1);
		}
		st->arr = tmp;
		st->capacity = newcapacity;
	}
}
void STPush(ST* st, STDataType x)
{
	assert(st);
	STEnough(st);
	st->arr[st->top] = x;
	st->top++;
}
void STPop(ST* st)
{
	assert(st && st->top);
	st->top--;
}
STDataType STTop(ST* st)
{
	assert(st && st->top);
	return st->arr[st->top - 1];
}
bool STEmpty(ST* st)
{
	assert(st);
	return st->top == 0;
}
int STSize(ST* st)
{
	assert(st);
	return st->top;
}
void STDestroy(ST* st)
{
	assert(st);
	if (st->arr!=NULL)
	{
		free(st->arr);
	}
	st->arr = NULL;
	st->capacity = st->top = 0;
}